package cheqex.dao;

import java.util.ArrayList;
import java.util.List;

import org.apache.torque.util.Criteria;

import com.workingdogs.village.Record;

public class LatestActivitiesPeer
    extends cheqex.dao.BaseLatestActivitiesPeer
{
	private static int id;
	
	public static boolean addActivity(java.sql.Date date, String activity){
		String query = "SELECT MAX(ID) from LatestActivities";
		
		try{
			List<Record> records = (List<Record>)LatestActivitiesPeer.executeQuery(query);
			Record record = ((List<Record>)records).get(0);
			id = record.getValue(1).asInt();
			
			Criteria criteria = new Criteria();
			criteria.add(LatestActivitiesPeer.ID, id+1);
			criteria.add(LatestActivitiesPeer.DATE,date);
			criteria.add(LatestActivitiesPeer.ACTIVITY, activity);			
			
			try{
				WeeklyRemarksPeer.doInsert(criteria);
				return true;
			}catch(Exception e){
				e.printStackTrace();
				return false;
			}
			
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
	}
	
	public static int getID(){
		String query = "SELECT MAX(ID) from LatestActivities";
		try{
			List<Record> records = (List<Record>)LatestActivitiesPeer.executeQuery(query);
			Record record = ((List<Record>)records).get(0);
			id = record.getValue(1).asInt();
			return id;
		}catch(Exception e){
			e.printStackTrace();
			return -1;
		}
	}
	
	public static List<LatestActivities> retrieveActivities(int idNum){
		Criteria criteria = new Criteria();
		criteria.add(LatestActivitiesPeer.ID, idNum);
		
		try{
			return (List<LatestActivities>)LatestActivitiesPeer.doSelect(criteria);
		}catch(Exception e){
			e.printStackTrace();
			return new ArrayList<LatestActivities>();
		}
	}
}
